package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.ItemRecommendService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.PanelDto;
import com.mall.shopping.dto.RecommendResponse;
import com.mall.user.annotation.Anoymous;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

/**
 * @author Connor
 * @date 2020/12/21
 */
@RestController
@RequestMapping("shopping")
public class RecommendController {

    @Reference(timeout = 3000,check = false)
    private ItemRecommendService productRecommendService;

    @Anoymous
    @GetMapping("recommend")
    public ResponseData recommend() {

        RecommendResponse recommendResponse = productRecommendService.queryItemRecommend();
        if (recommendResponse.getCode().equals(ShoppingRetCode.SUCCESS.getCode())) {
            return new ResponseUtil<Set<PanelDto>>().setData(recommendResponse.getPanelContentItemDtos(), "success");
        } else {
            return new ResponseUtil<>().setErrorMsg("没有商品推荐");
        }
    }
}
